<?php
// Hämta en array av filer från disk

// Spara filer
class FileUploadHandler {
	public $dir = "files";
	public function getFiles() {
		$dir = $this -> dir;
		$files = scandir($dir);
		return $files;
	}
	public function saveFiles() {
		if ($_FILES["file"]["error"] > 0) {
			return "något blev fel när filen skulle laddas upp";
		} else {
			//echo "Upload: " . $_FILES["file"]["name"] . "<br />";
			//echo "Type: " . $_FILES["file"]["type"] . "<br />";
			//echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
			//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

			if (file_exists("files/" . $_FILES["file"]["name"])) {
				return "En fil med namnet " . $_FILES["file"]["name"] . " finns redan i foldern. ";
			} else {
				move_uploaded_file($_FILES["file"]["tmp_name"], "files/" . $_FILES["file"]["name"]);
				//echo "Stored in: " . "files/" . $_FILES["file"]["name"];
				unset($_POST['upload']);
				return "Filen " . $_FILES["file"]["name"] . "laddades upp utan problem";
			}
		}
	}
}
?>